//
//  MYGExpertTaskDetailCell.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/5/30.
//

import UIKit
import QMUIKit

class MYGExpertTaskDetailCell: UITableViewCell {

    var model:MYGAcademicExpertSession_infoModel?{
        didSet {
            guard let item = model else {return}
            
            let arr = item.sessionTime.components(separatedBy: " ")
            
            let dateString:String = arr.first!
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = "yyyy-MM-dd"
            if let date = dateFormatter.date(from: dateString) {
                // 转换成功，得到Date对象
                let dateFormatter = DateFormatter()
                dateFormatter.dateFormat = "MM月dd日"
                let dateString = dateFormatter.string(from: date)
                timeLabel.text = dateString
            } else {
                // 转换失败
            }
            
            subtimeLabel.rz.colorfulConfer {confer in
                confer.text("时间：")?.font(.regular(14)).textColor(.rgba(147, 147, 147, 1))
                confer.text("\(item.sessionTime)")?.font(.regular(14)).textColor(.rgba(69, 70, 77, 1))
            }
            titleLab.rz.colorfulConfer {confer in
                confer.text("题目：")?.font(.regular(14)).textColor(.rgba(147, 147, 147, 1))
                confer.text("\(item.sessionCn)")?.font(.regular(14)).textColor(.rgba(69, 70, 77, 1))
            }
            forumLabel.rz.colorfulConfer {confer in
                confer.text("论坛：")?.font(.regular(14)).textColor(.rgba(147, 147, 147, 1))
                confer.text("\(item.roomCn)")?.font(.regular(14)).textColor(.rgba(69, 70, 77, 1))
            }
            mettingLabel.rz.colorfulConfer {confer in
                confer.text("会场：")?.font(.regular(14)).textColor(.rgba(147, 147, 147, 1))
                confer.text("\(item.location)")?.font(.regular(14)).textColor(.rgba(69, 70, 77, 1))
            }
            roleLabel.rz.colorfulConfer {confer in
                confer.text("角色：")?.font(.regular(14)).textColor(.rgba(147, 147, 147, 1))
                confer.text("\(item.expertRoleCn)")?.font(.regular(14)).textColor(.rgba(69, 70, 77, 1))
            }
            
        }
    }
    
    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        contentView.backgroundColor = .white
        configUI()
 
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: - UI
    private func configUI() {
        contentView.backgroundColor = .white
        
        contentView.addSubview(timeLabel)
        contentView.addSubview(line)
        contentView.addSubview(subtimeLabel)
        contentView.addSubview(titleLab)
        contentView.addSubview(forumLabel)
        contentView.addSubview(mettingLabel)
        contentView.addSubview(roleLabel)
        
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(17.5)
            make.top.equalToSuperview()
            make.height.equalTo(31.5)
        }
        
        line.snp.makeConstraints { make in
            make.left.equalTo(timeLabel)
            make.top.equalTo(timeLabel.snp.bottom)
            make.height.equalTo(1.5)
            make.right.equalToSuperview().inset(17.5)
        }
        
        subtimeLabel.snp.makeConstraints { make in
            make.left.equalTo(timeLabel)
            make.top.equalTo(line.snp.bottom).offset(19)
            make.height.equalTo(20)
        }
        
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(timeLabel)
            make.top.equalTo(subtimeLabel.snp.bottom)
            make.height.equalTo(20)
        }
        forumLabel.snp.makeConstraints { make in
            make.left.equalTo(timeLabel)
            make.top.equalTo(titleLab.snp.bottom)
            make.height.equalTo(20)
        }
        mettingLabel.snp.makeConstraints { make in
           make.left.equalTo(timeLabel)
           make.top.equalTo(forumLabel.snp.bottom)
            make.height.equalTo(20)
       }
        roleLabel.snp.makeConstraints { make in
           make.left.equalTo(timeLabel)
           make.top.equalTo(mettingLabel.snp.bottom)
            make.height.equalTo(20)
       }
        
    }

    private lazy var timeLabel: QMUILabel = {
        let label = QMUILabel()
        label.font = .regular(15)
        label.textColor = .rgba(255, 255, 255, 1)
        label.backgroundColor = .rgba(59, 55, 222, 1)
        label.layer.cornerRadius = 5
        label.layer.masksToBounds = true
        label.layer.maskedCorners = [.layerMinXMinYCorner,.layerMaxXMinYCorner]
        label.contentEdgeInsets = UIEdgeInsets(inset: 5)
        return label
    }()
    
    private lazy var line:UIView = {
        let line = UIView()
        line.backgroundColor = .rgba(59, 55, 222, 1)
        return line
    }()
    
    private lazy var subtimeLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(97, 97, 97, 1)
        label.numberOfLines = 0
        return label
    }()

    private lazy var titleLab: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(97, 97, 97, 1)
        return label
    }()
    
    private lazy var forumLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(12)
        label.textColor = .rgba(27, 79, 218, 1)
        return label
    }()
    private lazy var mettingLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(97, 97, 97, 1)
        return label
    }()
    private lazy var roleLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(97, 97, 97, 1)
        label.numberOfLines = 0
        return label
    }()

}
